# Ubuntu system command basics

## System Info

- `lsb_release -a`: get basic OS version info
- `lscpu`: get processor info
  - `uname -a`: Linux kernel name
  - `uname -r`: kernel release
  - `uname -v`: kernel version
  - `uname -n`: node hostname
  - `uname --m`: machine hardware arch
  - `uname -p`: processor type
  - `uname -i`: hardware platform
  - `uname -o`: OS info
- `lshw`: gets extensive machine info, option `-short` flag for condensed

`systemctl list-units --type=service` lists the systemd services/processes that are on the machine.

Each unit has a corresponding unit file. These unit files are usually located in the following directories:

- The /usr/lib/systemd/user/ directory is the default location where unit files are installed by packages. Unit files in the default directory should not be altered.
- The /run/systemd/system/ directory is the runtime location for unit files.
- The /etc/systemd/system/ directory stores unit files that extend a service. This directory will take precedence over unit files located anywhere else in the system.

## User Info

`/etc/passwd` contains all users on the system and information about them.

`id [USER]` displays the uid, primary group, and secondary groups

`useradd name` will create a new user, name.
`passwd name` will prompt the creation/update of a user's password.

> The `adduser` package streamlines this process, it will need to be apt installed.

`/etc/group` contains all of the groups created on the system.

`groups [USER]` displays the secondary groups only for the user

`sudo usermod -g primary_group example user` will change the primary group the user belongs to. Users require a primary group - files they create will be associated with this group.

`sudo usermod -a -G second_example_group example_user` will add example_user to the second_example_group group.

## Package Info

`dpkg -l` lists installed package on the host.

`apt list --installed | grep -w "\[installed\]"` list packages I have personally apt installed

Using `apt list --installed` generates a full list of installations. Each program is listed as:

- `[installed]`: indicates the package installed manually from the repository list.
- `[installed, automatic]`: means the package installed automatically as a dependency for another installation.
- `[installed, local]`: indicates the package is not from the official repository list.
